From f184ec4f06b08aa7070e5aa3de4abdaea0e6baf5 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Sun, 21 Dec 2014 01:41:02 -0500 Subject: [PATCH] Update to new-style rustc CLI args --- src/cargo/ops/cargo_rustc/mod.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index c08e060c6..82340b575 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -46,6 +46,10 @@ pub struct TargetConfig { /// The second element of the tuple returned is the target triple that rustc /// is a host for. pub fn rustc_version() -> CargoResult<(String, String)> { + rustc_new_version().or_else(|_| rustc_old_version()) +} + +pub fn rustc_old_version() -> CargoResult<(String, String)> { let output = try!(try!(util::process("rustc")) .arg("-v") .arg("verbose") @@ -65,6 +69,25 @@ pub fn rustc_version() -> CargoResult<(String, String)> { Ok((output, triple)) } +pub fn rustc_new_version() -> CargoResult<(String, String)> { + let output = try!(try!(util::process("rustc")) + .arg("-vV") + .exec_with_output()); + let output = try!(String::from_utf8(output.output).map_err(|_| { + internal("rustc -v didn't return utf8 output") + })); + let triple = { + let triple = output.as_slice().lines().filter(|l| { + l.starts_with("host: ") + }).map(|l| l.slice_from(6)).next(); + let triple = try!(triple.require(|| { + internal("rustc -v didn't have a line for `host:`") + })); + triple.to_string() + }; + Ok((output, triple)) +} + // This is a temporary assert that ensures the consistency of the arguments // given the current limitations of Cargo. The long term fix is to have each // Target know the absolute path to the build location. -- 2.30.2